import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由el-breadcrumb在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }dispose/incidentHandle
 */
let prefix = ''
if (window.__POWERED_BY_QIANKUN__ && window.parentType == 'hash') {
  prefix = '/zjgapp' // /zjgapp为主应用的activeRule
  window.prefix = '/zjgapp'
}
// 公共路由
export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '*',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },

  // {
  //   path: prefix + '/'
  //   redirect: '/mlk/accessProduct'
  // },

  /** =============================星河路由========================== */
  {
    path: prefix + '/mlk',
    // redirect: '/mlk/accessProduct',
    component: () => import('@/views/index.vue'),
    children: [
      {
        path: 'accessProduct',
        name: 'mlk_product',
        component: () => import('@/views/milkyway/product'),
        meta: { title: '接入产品', keepAlive: false }
      },
      {
        path: 'access/datasource',
        name: 'mlk_access_datasource',
        component: () => import('@/views/milkyway/datasource/access/index'),
        meta: { title: '接入数据源', keepAlive: false }
      },
      {
        path: 'access/outputDatasource',
        name: 'mlk_output_datasource',
        component: () => import('@/views/milkyway/datasource/output'),
        meta: { title: '输出数据源', keepAlive: false }
      },
      {
        path: 'access/rule',
        name: 'mlk_access_rule',
        component: () => import('@/views/milkyway/accessRule/index'),
        meta: { title: '接入规范管理', keepAlive: true }
      },
      {
        path: 'task/taskList',
        name: 'mlk_task',
        component: () => import('@/views/milkyway/task/taskList'),
        meta: { title: '任务管理', keepAlive: false }
      },
      {
        path: 'task/jobScheduleList',
        name: 'mlk_jobSchedule',
        component: () => import('@/views/milkyway/task/jobScheduleList'),
        meta: { title: '作业管理', keepAlive: false }
      },
      {
        path: 'task/errorAlarm',
        name: 'mlk_errorAlarm',
        component: () => import('../views/milkyway/errorAlarm/index.vue'),
        meta: { title: '日志异常', keepAlive: false }
      },
      {
        path: 'task/unparsedLogs',
        name: 'unparsedLogs',
        component: () => import('@/views/milkyway/unparsedLogs'),
        meta: { title: '未解析日志', keepAlive: false }
      },
      {
        path: 'metaData',
        name: 'mlk_metaData',
        component: () => import('@/views/milkyway/metadata/index'),
        meta: { title: '元数据管理', keepAlive: false }
      },
      {
        path: 'mappingDict',
        name: 'mlk_mappingDict',
        component: () => import('@/views/milkyway/dict/mappingDict'),
        meta: { title: '映射字典管理', keepAlive: false }
      },
      {
        path: 'commonDict',
        name: 'mlk_commonDict',
        component: () => import('@/views/milkyway/dict/commonDict'),
        meta: { title: '公共字典管理', keepAlive: false }
      },
      {
        path: 'dictDataList/:id?',
        name: 'mlk_dictDataList',
        component: () => import('@/views/milkyway/dict/commonDictDataList'),
        meta: { title: '字典管理列表', keepAlive: false }
      },
      {
        path: 'taskAdd/:id?',
        name: 'mlk_taskAdd',
        component: () => import('@/views/milkyway/task/taskAdd'),
        meta: { title: '新增任务', keepAlive: false }
      },
      {
        path: 'access/rule/ruleAdd/:id',
        name: 'mlk_rule_add',
        component: () => import('@/views/milkyway/accessRule/add'),
        meta: { title: '新增接入规则', keepAlive: false }
      },
      {
        path: 'home',
        name: 'mlk_home',
        component: () => import('../views/milkyway/home'),
        meta: { title: '首页', keepAlive: false }
      },
      {
        path: 'accessInformation:id?',
        prop: true,
        name: 'mlk_accessInformation',
        component: () => import('../views/milkyway/home/components/accessInformation.vue'),
        meta: { title: '各产品接入情况页', keepAlive: false }
      }
    ]
  },
  /** =============================妙算路由======================= */
  {
    path: prefix + '/icp',
    // redirect: '/icp/metrics',
    component: () => import('@/views/index.vue'),
    children: [
      {
        path: 'home',
        component: () => import('@/views/icp/home/index'),
        meta: { title: '数据分析', keepAlive: false }
      },
      {
        path: 'metrics',
        name: 'icp_metrics',
        component: () => import('@/views/icp/metrics/index'),
        meta: { title: '监测指标', keepAlive: true }
      },
      {
        path: 'rule',
        name: 'icp_rule',
        component: () => import('@/views/icp/rule/index'),
        meta: { title: '监测规则', keepAlive: true }
      }, {
        path: 'ruleDetail',
        name: 'icp_rule_detail',
        component: () => import('@/views/icp/rule/component/ruleDetail.vue'),
        meta: { title: '规则详情', keepAlive: false }
      },
      {
        path: 'model',
        hidden: true,
        component: () => import('@/views/icp/model'),
        name: 'icp_model',
        meta: { title: '监测模型', keepAlive: false }
      },
      {
        path: 'data/entity',
        name: 'icp_entity',
        component: () => import('@/views/icp/entity/index'),
        meta: { title: '实体信息', keepAlive: false }
      },
      {
        path: 'data/behavior',
        hidden: true,
        component: () => import('@/views/icp/behavior'),
        name: 'icp_behavior',
        meta: { title: '行为信息', keepAlive: false }
      },
      {
        path: 'data/refdata',
        hidden: true,
        component: () => import('@/views/icp/refdata'),
        name: 'icp_refdata',
        meta: { title: '引用数据管理', keepAlive: false }
      },
      {
        path: 'data/metricsProperties',
        name: 'icp_metrics_properties',
        component: () => import('@/views/icp/metrics/properties'),
        meta: { title: '指标属性', keepAlive: false }
      },
      {
        path: 'metricsDetail',
        name: 'icp_metrics_detail',
        component: () => import('@/views/icp/metrics/detail'),
        meta: { title: '指标详情', keepAlive: false }
      },
      {
        path: 'baseline',
        name: 'icp_baseline',
        component: () => import('@/views/icp/baseline'),
        meta: { title: '基线配置', keepAlive: false }
      }
    ]
  },

  /** -------妙算  */
  /** =============================研判路由======================= */
  {
    path: prefix + '/dispose',
    // redirect: '/dispose/incidentHandle',
    component: () => import('@/views/index'),
    children: [
      {
        path: 'logTracing',
        component: () => import('@/views/dispose/logTracing/index'),
        meta: { title: '日志溯源', keepAlive: false }
      },
      {
        path: 'emergencyResponsePlan',
        component: () => import('@/views/dispose/emergencyResponsePlan/index'),
        meta: { title: '应急响应预案', keepAlive: false }
      },
      {
        path: 'incidentHandle',
        name: 'incidentHandle',
        component: () => import('@/views/dispose/incidentHandle/index'),
        meta: { title: '事件处置', keepAlive: true }
      },
      {
        path: 'incidentList',
        name: 'incidentList',
        component: () => import('@/views/dispose/incidentHandle/incidentList'),
        meta: { title: '事件处置列表', keepAlive: false }
      },
      {
        path: 'tasks',
        component: () => import('@/views/dispose/incidentHandle/tasks'),
        meta: { title: '待办事项', keepAlive: false }
      },
      {
        path: 'list',
        name: 'dispose_list',
        component: () => import('@/views/dispose/incidentHandle/list'),
        meta: { title: '全部工单', keepAlive: false }
      },
      {
        path: 'listCreate',
        component: () => import('@/views/dispose/incidentHandle/list/listEdit.vue'),
        meta: { title: '新增', keepAlive: false }
      },
      {
        path: 'listInfo',
        name: 'workbenchListInfo',
        component: () => import('@/views/dispose/incidentHandle/list/listInfo.vue'),
        meta: { title: '查看工单', keepAlive: 'false' }
      },
      {
        path: 'incidentHandle/detail',
        component: () => import('@/views/dispose/incidentHandle/detail'),
        meta: { title: '事件详情', icon: 'dashboard' }
      },
      {
        path: 'search',
        name: 'portray_search',
        component: () => import('@/views/dispose/entityPortrait/search'),
        meta: { title: '搜索', keepAlive: true }
      },
      {
        path: 'entityPortrait/:id?',
        name: 'dispose_portrait',
        component: () => import('@/views/dispose/entityPortrait/index'),
        meta: { title: '用户画像', keepAlive: false }
      }
    ]
  },

  /** 报告中心 */
  {
    path: prefix + '/report',
    // redirect: '/report/templateManage',
    component: () => import('@/views/index'),
    children: [
      //  报告中心
      {
        path: 'templateManage',
        component: () => import('@/views/reportCenter/templateManage/index.vue'),
        name: 'assetsComparison',
        meta: { title: '模板管理', keepAlive: false }
      }, {
        path: 'safetyReportManagement',
        component: () => import('@/views/reportCenter/safetyReportManagement/index.vue'),
        name: 'safetyReportManagement',
        meta: { title: '安全报告管理', keepAlive: false }
      }
    ]
  },
  /** =============================资产路由======================= */
  {
    path: prefix + '/assets',
    // redirect: '/assets/assetsComparison',
    component: () => import('@/views/index'),
    children: [
      {
        path: 'unknownAssets',
        component: () => import('@/views/assets/unknownAssets/index.vue'),
        name: 'unknownAssets',
        meta: { title: '未知资产管理', keepAlive: false }
      },
      {
        path: 'assetsComparison',
        component: () => import('@/views/assets/assetsComparison/comparisonIndex.vue'),
        name: 'assetsComparison',
        meta: { title: '资产比对', keepAlive: false }
      },
      {
        path: 'network',
        hidden: true,
        component: () => import('@/views/assets/network/network'),
        name: 'network',
        meta: { title: '网络信息维护', keepAlive: false }
      },
      {
        path: 'secDomain',
        hidden: true,
        component: () => import('@/views/assets/secdomain/secDomain'),
        name: 'secDomain',
        meta: { title: '安全域维护', keepAlive: false }
      },
      /** -------设备信息--------  */
      {
        path: 'device/host',
        hidden: true,
        component: () => import('@/views/assets/device/host/host'),
        name: 'host',
        meta: { title: '终端信息维护', keepAlive: false }
      },
      {
        path: 'device/server',
        hidden: true,
        component: () => import('@/views/assets/device/server/server'),
        name: 'server',
        meta: { title: '服务器信息维护', keepAlive: false }
      },
      {
        path: 'device/netDevice',
        hidden: true,
        component: () => import('@/views/assets/device/net/netDevice'),
        name: 'net',
        meta: { title: '网络设备维护', keepAlive: false }
      },
      {
        path: 'device/secproduct',
        hidden: true,
        component: () => import('@/views/assets/device/secProduct/secProduct'),
        name: 'secproduct',
        meta: { title: '安全保密产品', keepAlive: false }
      },
      {
        path: 'device/storageMedium',
        hidden: true,
        component: () => import('@/views/assets/device/storageMedium/storageMedium'),
        name: 'storageMedium',
        meta: { title: '存储介质产品', keepAlive: false }
      },
      {
        path: 'device/outside',
        hidden: true,
        component: () => import('@/views/assets/device/outside/outsideEquipment'),
        name: 'outsideeEquipment',
        meta: { title: '外部设备维护', keepAlive: false }
      },
      {
        path: 'device/unknownEquipment',
        hidden: true,
        component: () => import('@/views/assets/device/unknown/unknownEquipment'),
        name: 'unknownEquipment',
        meta: { title: '未知设备维护', keepAlive: false }
      },
      {
        path: 'device/all',
        hidden: true,
        component: () => import('@/views/assets/device/all/assetsAll'),
        name: 'assetsAll',
        meta: { title: '全部资产维护', keepAlive: false }
      },
      {
        path: 'device/other',
        hidden: true,
        component: () => import('@/views/assets/device/other/otherEquipment'),
        name: 'otherEquipment',
        meta: { title: '其它设备维护', keepAlive: false }
      },
      /** -------设备信息 end--------  */
      {
        path: 'software',
        hidden: true,
        component: () => import('@/views/assets/software/software'),
        name: 'softwareSystem',
        meta: { title: '软件系统维护', keepAlive: false }
      },
      {
        path: 'org',
        hidden: true,
        component: () => import('@/views/assets/org/assetsOrg'),
        name: 'assetsOrg',
        meta: { title: '组织机构维护', keepAlive: false }
      },
      {
        path: 'user',
        hidden: true,
        component: () => import('@/views/assets/user/assetsUser'),
        name: 'assetsUser',
        meta: { title: '用户', keepAlive: false }
      }
    ]
  },
  /** =============================审批管理路由======================= */
  {
    path: prefix + '/approval',
    // redirect: '/approval/printBurn',
    component: () => import('@/views/index'),
    children: [
      {
        path: 'applicationAccess',
        component: () => import('@/views/approval/applicationAccess/index.vue'),
        name: 'applicationAccess',
        meta: { title: '应用访问审批信息', keepAlive: false }
      },
      {
        path: 'externalAccess',
        component: () => import('@/views/approval/externalAccess/index.vue'),
        name: 'externalAccess',
        meta: { title: '外部接入权限审批信息', keepAlive: false }
      },
      {
        path: 'maintenancePermissions',
        component: () => import('@/views/approval/maintenancePermissions/index.vue'),
        name: 'maintenancePermissions',
        meta: { title: '运维权限审批信息', keepAlive: false }
      },
      {
        path: 'printBurn',
        component: () => import('@/views/approval/printBurn/index.vue'),
        name: 'printBurn',
        meta: { title: '打印刻录审批信息', keepAlive: false }
      }
    ]
  }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = []

// 防止连续点击多次路由报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// 宝兰德的是哈希模式，打包部署自己的服务器的时候是history模式
const isUM = window.versionType == 'webgate'
export default new Router({
  base: window.__POWERED_BY_QIANKUN__ ? '/zjgapp/' : '/zjg/',
  mode: isUM ? 'hash' : 'history',
  routes: constantRoutes
})
